package com.soft.controller;

import com.soft.entity.Student;
import com.soft.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping("/quallerAll")
    public List<Student> quallerAll(){
        return studentService.quallerAll();
    }

    @RequestMapping("/insert")
    public String insert(String name,String age,String address,String class_id){
        int num= studentService.insert(name,age,address,class_id);
        if(num==1){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }

    @RequestMapping("/UpdateNameById")
    public String UpdateNameById(int id,String name){
        int num=studentService.updateNameById(id,name);
        if(num==1){
            return "更新成功";
        }else  {
            return "更新失败";
        }
    }

    @RequestMapping("delete")
    public String delete(int id){
        int num=studentService.delete(id);
        if(num==1){
            return "删除成功";
        }else  {
            return "删除失败";
        }
    }

    @RequestMapping("/updateStudentClass")
    public String  updateStudentClass(String name,String className){
        int num=studentService.updateStudentClass(name,className);
        if(num==1){
            return "更改学生班级成功";
        }else  {
            return "更改学生班级失败";
        }
    }
}
